package com.chart.factory;

import java.io.IOException;

import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

import com.chart.vo.Chart;

public class PiePlotFactory<T extends Number> extends PieChartFactory<T> {

	@Override
	@Deprecated
	public void setData(Chart<T> chart) {
		super.setChart(chart);
	}

	@Override
	@Deprecated
	public Chart<T> createChart() throws IOException {
		Chart<T> chart = super.getChart();
		if(null == chart) {
			return null;
		}
		
		return this.createChart(chart);
	}
	
	public Chart<T> createChart(Chart<T> chart) throws IOException {
		super.setChart(chart);
		PieDataset dataSet = (DefaultPieDataset) super.createDataset(chart);
		Plot plot = new PiePlot(dataSet);
		
		((PiePlot) plot).setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2} [{1}]"));
//		((PiePlot) plot).setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
		try {
			chart = super.create(plot);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return chart;
	}

}
